package HomeWork20241215.Phone;

import java.util.Scanner;

/*
 * 计算出三部手机的平均价格
 * */
public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Phone[] phones = new Phone[3];

        for (int i = 0; i < phones.length; i++) {
            System.out.println("请输入第 " + (i + 1) + " 部手机的信息：");
            System.out.print("品牌: ");
            String brand = scanner.nextLine();
            System.out.print("价格: ");
            double price = scanner.nextDouble();
            // 读取换行符
            scanner.nextLine();
            System.out.print("颜色: ");
            String color = scanner.nextLine();

            phones[i] = new Phone(brand, price, color);
        }

        double sum = 0;
        System.out.println("\n您输入的手机信息如下：");
        for (Phone phone : phones) {
            System.out.println(phone.toString());
            sum += phone.getPrice();
        }

        // 计算平均价格
        double averagePrice = sum / phones.length;
        System.out.printf(phones.length + "部手机的平均价格：%.2f%n",averagePrice);
    }
}
